Crate tide[−][src]
Expand description
Tide is a minimal and pragmatic Rust web application framework built for rapid development. It comes with a robust set of features that make building async web applications and APIs easier and more fun.
Getting started
In order to build a web app in Rust you need an HTTP server, and an async
runtime. After running cargo init
add the following lines to your
Cargo.toml
file:
tide = "0.14.0"
async-std = { version = "1.6.0", features = ["attributes"] }
serde = { version = "1.0", features = ["derive"] }
Examples
Create an HTTP server that receives a JSON body, validates it, and responds with a confirmation message.
use tide::Request;
use tide::prelude::*;
#[derive(Debug, Deserialize)]
struct Animal {
name: String,
legs: u8,
}
#[async_std::main]
async fn main() -> tide::Result<()> {
let mut app = tide::new();
app.at("/orders/shoes").post(order_shoes);
app.listen("127.0.0.1:8080").await?;
Ok(())
}
async fn order_shoes(mut req: Request<()>) -> tide::Result {
let Animal { name, legs } = req.body_json().await?;
Ok(format!("Hello, {}! I've put in an order for {} shoes", name, legs).into())
}
$ curl localhost:8080/orders/shoes -d '{ "name": "Chashu", "legs": 4 }'
Hello, Chashu! I've put in an order for 4 shoes
$ curl localhost:8080/orders/shoes -d '{ "name": "Mary Millipede", "legs": 750 }'
number too large to fit in target type
See more examples in the examples directory.
Re-exports
pub use http_types as http;
Modules
Traits for conversions between types.
Types that represent HTTP transports and binding
Event logging types.
The Tide prelude.
HTTP Security Headers.
Tide session support
Server-Sent Events (SSE) types.
Miscellaneous utilities.
Structs
A streaming HTTP body.
The error type for HTTP operations.
The remainder of a middleware chain, including the endpoint.
A redirection endpoint.
An HTTP request.
An HTTP response
Response Builder
A handle to a route.
An HTTP server.
Enums
HTTP response status codes.
Traits
An HTTP request handler.
Middleware that wraps around the remaining middleware chain.
Provides the status
method for Result
and Option
.
Functions
Create a new Tide server.
Create a new Tide server with shared application scoped state.
Type Definitions
A specialized Result type for Tide.